package demo01;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.stream.Collectors;

public class zuoye05 {
	public static void main(String[] args) throws IOException {
//		File file = new File("work.txt");
//		boolean created = file.createNewFile();
//		System.out.println(created);
//		FileOutputStream fos=new FileOutputStream(file);
//		byte[] b="2-1-9-4-7-8".getBytes();
//		fos.write(b);
//		fos.close();

		ArrayList<Character>list=new ArrayList<>();
		
		FileReader fr=new FileReader("work.txt");
		int ch=0;
		while((ch=fr.read())!=-1)
		{
			list.add((char)ch);
			System.out.print((char)ch);
		}
		String collect = list.stream().filter(t->t!='-').sorted().map(t->t+"").collect(Collectors.joining("-"));
		System.out.print(collect);
		FileOutputStream fos=new FileOutputStream("work.txt");
		byte[] bb=collect.getBytes();
		fos.write(bb);
		fos.close();
	}
}
